import 'package:flutter/material.dart';
import 'package:vector_math/vector_math.dart' show radians;

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'World Map Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: WorldMapScreen(),
    );
  }
}

class WorldMapScreen extends StatefulWidget {
  @override
  _WorldMapScreenState createState() => _WorldMapScreenState();
}

class _WorldMapScreenState extends State<WorldMapScreen> {
  double _rotation = 0.0;

  void _rotateEarth(double delta) {
    setState(() {
      _rotation += delta;
    });
  }

  void _showTaskDetails() {
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return TaskDetailsDialog();
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('World Map'),
      ),
      drawer: Drawer(
        child: ListView(
          padding: EdgeInsets.zero,
          children: <Widget>[
            DrawerHeader(
              decoration: BoxDecoration(
                color: Colors.blue,
              ),
              child: Text(
                'Progress',
                style: TextStyle(
                  color: Colors.white,
                  fontSize: 24,
                ),
              ),
            ),
            ListTile(
              title: Text('Annual Goal: 85%'),
              subtitle: Text('Quarter Goal: 60%'),
            ),
            ListTile(
              title: Text('Milestones'),
              subtitle: Text('Key Nodes'),
            ),
          ],
        ),
      ),
      body: Stack(
        children: [
          GestureDetector(
            onPanUpdate: (details) {
              _rotateEarth(details.delta.dx / 100);
            },
            child: Transform.rotate(
              angle: radians(_rotation),
              child: Image.asset('assets/images/earth.png'),
            ),
          ),
          Positioned(
            bottom: 20,
            left: 20,
            child: FloatingActionButton(
              onPressed: () {
                // Generate smart tasks based on location
              },
              child: Icon(Icons.add),
            ),
          ),
          Positioned(
            bottom: 20,
            right: 20,
            child: FloatingActionButton(
              onPressed: () {
                // Start 10-second note capture
              },
              child: Icon(Icons.flash_on),
            ),
          ),
        ],
      ),
    );
  }
}

class TaskDetailsDialog extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Dialog(
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(16),
      ),
      elevation: 0.0,
      backgroundColor: Colors.transparent,
      child: Container(
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(16),
        ),
        padding: EdgeInsets.all(16),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Text(
              'Flutter Canyon',
              style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
            ),
            SizedBox(height: 16),
            Text(
              'Complete 5 Widget cases → Unlock terrain lighting effects',
              style: TextStyle(fontSize: 16),
            ),
            SizedBox(height: 16),
            Text(
              'Difficulty: Intermediate',
              style: TextStyle(fontSize: 16),
            ),
            SizedBox(height: 16),
            Text(
              'Memory Consolidation Tip: Repeat this task every 24 hours for 3 times',
              style: TextStyle(fontSize: 16),
            ),
            SizedBox(height: 16),
            Text(
              'Gene Preview: Complete this task to activate LOGIC_4 gene fragment',
              style: TextStyle(fontSize: 16),
            ),
          ],
        ),
      ),
    );
  }
}